package com.scoy.honeymei.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

import com.scoy.honeymei.R;
import com.scoy.honeymei.bean.WithdrawBean;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @ClassName: NormalAdapter$
 * @Description:
 * @Author: GaoZhan
 * @CreateDate: 2019/8/26/0026$ 下午 17:03$
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/8/26/0026$ 下午 17:03$
 * @UpdateRemark: 更新内容
 */
public class WithdrawAdapter extends RecyclerView.Adapter {
    private Context context;
    private ArrayList<WithdrawBean.CheckoutBean> datalist;
    private TextView notv;

    public WithdrawAdapter(Context context, ArrayList<WithdrawBean.CheckoutBean> datalist, TextView notv) {
        this.context = context;
        this.datalist = datalist;
        this.notv = notv;
    }

    public interface OnOneClick {
        void oneClick(int pos);
    }

    OnOneClick onOneClick;

    public void setOnOneClick(OnOneClick onOneClick) {
        this.onOneClick = onOneClick;
    }

    public interface OnTwoClick {
        void twoClick(int pos);
    }

    OnTwoClick onTwoClick;

    public void setOnTwoClick(OnTwoClick onTwoClick) {
        this.onTwoClick = onTwoClick;
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_withdraw, parent, false);
        return new WithdrawHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        WithdrawHolder withdrawHolder = (WithdrawHolder) holder;
        WithdrawBean.CheckoutBean checkoutBean = datalist.get(position);
        withdrawHolder.wdTitleTv.setText("提现 " + checkoutBean.getMoney());
        withdrawHolder.mdTimeTv.setText(checkoutBean.getCreatetime());
        withdrawHolder.mdReasonTv.setText(checkoutBean.getContent());
        String status = checkoutBean.getStatus();
        if ("-1".equals(status)) {
            withdrawHolder.wdSignTv.setText("驳回");
            withdrawHolder.wdSignTv.setTextColor(context.getResources().getColor(R.color.colorMainRed));
        } else if ("0".equals(status)) {
            withdrawHolder.wdSignTv.setText("待审核");
            withdrawHolder.wdSignTv.setTextColor(context.getResources().getColor(R.color.colorMainGray3));
        } else if ("1".equals(status)) {
            withdrawHolder.wdSignTv.setText("已审核");
            withdrawHolder.wdSignTv.setTextColor(context.getResources().getColor(R.color.colorMainGray3));
        }

    }

    @Override
    public int getItemCount() {
        int iCount = datalist == null ? 0 : datalist.size();
        if (iCount == 0) {
            notv.setVisibility(View.VISIBLE);
        } else {
            notv.setVisibility(View.GONE);
        }
        return iCount;
    }

    class WithdrawHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.wd_title_tv)
        TextView wdTitleTv;
        @BindView(R.id.wd_sign_tv)
        TextView wdSignTv;
        @BindView(R.id.md_time_tv)
        TextView mdTimeTv;
        @BindView(R.id.md_reason_tv)
        TextView mdReasonTv;
        @BindView(R.id.item_withdraw_llt)
        ConstraintLayout itemWithdrawLlt;

        WithdrawHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
